<template>
    <div class="zb-analysis">
            <item-layout class="statistics" title="统计信息">
                <template slot="afterTitle">
                    <p class="statistics-time">{{companyInfo.statisticsTime}}</p>
                </template>

                <div class="statistics-items">
                    <div v-for="item in statisticsArr" :key="item.title">
                        <div class="top">
                            <div class="num">{{item.num}}</div>
                            <div>{{typeName(item.type)}}</div>
                        </div>
                        <div class="title">{{item.title}}</div>
                    </div>
                </div>
            </item-layout>

            <div class="charts">
                <item-layout  title="年度项目统计">
                    <annual-project 
                    :options="yearProjectObj"
                    ></annual-project>
                </item-layout>

                <item-layout  title="月度项目金额规模统计">
                    <month-project-line :options="MonBiddingPriceList"></month-project-line>
                </item-layout>

                <item-layout  title="各类招标方式占比">
                    <bidding-style-new :options="bidwayList" style="margin-top:75px"></bidding-style-new>
                </item-layout>

                <!-- <item-layout  title="各类招标方式占比">
                    <bidding-style></bidding-style>
                </item-layout> -->

                <item-layout  title="行业招标占比">
                    <month-project-pie
                        :options="industryBidList">
                    </month-project-pie>
                </item-layout>

                <item-layout  title="中标企业注册资本分布">
                    <registered-capital :options="registeredcCapitalList"></registered-capital>
                </item-layout>

                <!-- <item-layout  title="中标企业年限及个数分布">
                    <age-count :options="ageCountList"></age-count>
                </item-layout> -->

                <item-layout  title="中标企业年限及个数分布" v-if="ageCountList[0].length <11">
                    <cooperative-enterprise-age :options="ageCountList"></cooperative-enterprise-age>
                </item-layout>
            </div>

            <div v-if="ageCountList[0].length >=11">
                <item-layout  title="中标企业年限及个数分布">
                    <cooperative-enterprise-age :options="ageCountList"></cooperative-enterprise-age>
                </item-layout>
            </div>

            <div class="block-item">
                <item-layout title="单位联系人及方式">
                    <div class="items">
                        <div v-for="(item,index) in analysisArr" :key="index">
                            <contacts :data="item"></contacts>
                        </div>
                    </div>
                    <my-pagination
                        class="pagination"
                        ref="analysispage"
                        v-model="analysisArr"
                        :action="`${$store.state.api.tbUrl}/zbanalysis/managerlist.json`"
                        :search="analysisPgData"
                        :text-align="'right'"
                        :auto-show="false"
                        :afterQuery="unitDetailsAfterQuery"
                    ></my-pagination>
                </item-layout>
            </div>

            <div class="mechanism block-item">
                <item-layout  title="合作代理机构">
                    <div class="mechanism-items" v-if="mechanismArr.length > 0">
                        <div class="mechanism-items-left">
                            <div class="mechanism-item">
                                <div> </div>
                                <div>项目数量</div>
                                <div>最近合作日期</div>
                            </div>
                            <div class="mechanism-item" v-for="(item,index) in mechanismArr.slice(0,5)" :key="index">
                                <div>{{item.company}}</div>
                                <div>{{item.nums}}<span v-show="item.nums">个</span></div>
                                <div>{{item.resdate}}</div>
                            </div>
                        </div>
                        
                        <div class="mechanism-items-right" v-if="mechanismArr.length > 5">
                            <div class="mechanism-item">
                                <div> </div>
                                <div>项目数量</div>
                                <div>最近合作日期</div>
                            </div>
                            <div class="mechanism-item" v-for="(item,index) in mechanismArr.slice(5,10)" :key="index">
                                <div>{{item.company}}</div>
                                <div>{{item.nums}}<span v-show="item.nums">个</span></div>
                                <div>{{item.resdate}}</div>
                            </div>
                        </div>

                    </div>

                    <empty-list v-if="mechanismArr.length == 0">
                        <span>暂无数据</span>
                    </empty-list>
                    
                    <my-pagination
                        class="pagination"
                        ref="page"
                        v-model="mechanismArr"
                        :action="`${$store.state.api.tbUrl}/zbanalysis/partnersinfo.json`"
                        :search="hzdlPgData"
                        :text-align="'right'"
                        :auto-show="false"
                        :afterQuery="cooperateAgentAfterQuery"
                        >
                    </my-pagination>

                </item-layout>
            </div>

            <div class="bottom">
                <div class="bottom-left">
                    <h3>招标动态 <span class="re-span">该数据以发布招标公告为准</span></h3>
                    <!-- :afterClick="similarItemsMD"   @titleClick="titleClick"  -->
                    <load-list 
                    ref="bidDynamicRef"
                    v-model="BidDynamic" 
                    :search="BidDynamicPgdata" 
                    :action="`${$store.state.api.tbUrl}/zbanalysis/getprojectlist.json`" 
                    @queryEnd="bidDynamicAfter"
                    >
                        <template>
                            <div 
                            class="bottom-right-items" 
                            v-for="(item , index) in BidDynamic" 
                            :key="index"
                            v-czc="['查企业-详情-招标分析（企业画像）', '点击列表' , '招标动态', index, `checkEnterpriseBid-list-bidDynamics`]">
                                <div class="title_con">
                                    <p>
                                        <span :title="item.name" @click="zbdtTitleClick(item)">{{index + 1 +'.' + item.name}}</span>
                                    </p>

                                    <div>
                                        <span>{{item.publishtime ||'-'}}</span>

                                        <collect-star
                                            :data="{objectguid: item.guid, objectname: item.name, objecttype: noticeCollType(item.noticetype), marktype: 'collect',}"
                                            :defaultVal="item.bj === '1'"
                                        ></collect-star>
                                    </div>
                                </div>
                                <div class="detail_con">
                                    <el-tag size="mini" type="info" v-if="!!item.area">{{item.area}}</el-tag>
                                    <el-tag size="mini" type="info" v-if="!!item.industry">{{item.industry}}</el-tag>
                                    <el-tag size="mini" type="info" v-if="!!item.noticetype">{{item.noticetype}}</el-tag>
                                    <el-tag size="mini" v-if="!!item.price">{{Math.floor(item.price)/10000 + '万元'}}</el-tag>
                                </div>
                            </div>
                        </template>
                    </load-list>
                </div>

                <div class="bottom-right">
                    <h3>中标企业</h3> 
                    <load-list 
                    ref="hzqyRef" 
                    v-model="hzqyList" 
                    :search="hzqyPgdata" 
                    :action="`${$store.state.api.tbUrl}/zbanalysis/winnersinfo.json`" 
                    @queryEnd="hzqyAfter"
                    >
                        <template>
                            <div 
                            class="bottom-right-items" 
                            v-for="(item , index) in hzqyList" 
                            :key="index"
                            v-czc="['查企业-详情-招标分析（企业画像）', '点击列表' , '中标企业', index, `checkEnterpriseBid-list-winEnterprise`]"
                            >
                                <div class="title_con">
                                    <p>
                                        <span @click="companyHandle(item)">{{index+1 + '.' + item.company}}</span>
                                    </p>
                                    <div>
                                        <collect-star
                                            :data="{ objectguid: item.guid, objectname: item.company, objecttype: 'enterprise', marktype: 'follow',}"
                                            :defaultVal="item.bj === '1'"
                                            :icon="['&#xeca2;', '&#xeca1;']"
                                        ></collect-star>
                                    </div>
                                </div>
                                <div class="detail_con">
                                    <span>中标次数：{{item.nums || ( item.nums == 0 ? 0 : '-')}}</span>
                                    <span>中标项目行业：{{item.industry || '-'}}</span>
                                    <br>
                                    <span>中标金额：{{ item.price == 0 ? '0' :  item.price == null ?  '-' : ((Math.floor(item.price)/10000).toFixed(4) + '万元')}}</span>
                                    <span>中标时间：{{item.resdate || '-'}}</span>
                                </div>
                            </div>
                        </template>
                    </load-list>
                </div>
            </div>
    </div>
</template>

<script>
import contacts from "./components/contacts.vue"
import itemLayout from './components/item-layout.vue';

import AnnualProject from './charts/annual-project.vue';
import monthProjectLine from './charts/month-project-line.vue';

import BiddingStyle from './charts/bidding-style.vue';
import BiddingStyleNew from './charts/bidding-style-new.vue';
import monthProjectPie from './charts/month-project-pie.vue';
import registeredCapital from './charts/registered-capital.vue'
import ageCount from './charts/age-count.vue';
import LoadList from '@components/sys/load-list.vue';
import CollectStar from '@components/sys/collect.vue';

//暂停使用
import cooperativeEnterprise from './charts/cooperative-enterprise.vue';
import cooperativeEnterpriseAge from './charts/cooperative-enterprise-age.vue';


import EmptyList from "@components/sys/empty-list";
import contentItem from "@/pages/application/info/components/item.vue";
import notice from '@/mixins/notice.js';

export default {
    mixins: [notice],
    components: { 
        contacts,
        itemLayout,

        AnnualProject,
        monthProjectLine,

        BiddingStyle,
        BiddingStyleNew,
        monthProjectPie,
        registeredCapital,
        ageCount,

        cooperativeEnterprise,
        cooperativeEnterpriseAge,
        
        contentItem,
        EmptyList,
        LoadList,
        CollectStar,
    },
    props: {
        isHavingPower: {
            type: Boolean,
            default: false
        },
        company:{
            type:String,
            default: ''
        }
    },
    data() {
        return {
            analysisPgData:{
                sortname:'a.notice_publish_time',
                pagesize:6,
                company:this.company
            },

            hzdlPgData:{
                sortname:"resdate",
                company:this.company
            },

            BidDynamicPgdata:{
                sortorder:'desc',
                sortname:'publishtime',
                pageindex:1,
                pagesize:10,
                company:this.company,
            },
            bidDynamicMaxpage:1,
            BidDynamicText:'向下滚动加载更多',

            hzqyPgdata:{
                sortorder:'desc',
                sortname:'resdate',
                pageindex:1,
                pagesize:10,
                company:this.company,
            },
            hzqyMaxpage:1,
            hzqyText:'向下滚动加载更多',

            color:["#3b68ff","#2ec75a","#ff8f00","#ff5454"],
    

            statisticsArr:[
                {
                    title:"项目数量",
                    num:'',
                    type:"1"
                },
                {
                    title:"项目金额",
                    num:'',
                    type:"2"
                },
                {
                    title:"中标企业数量",
                    num:'',
                    type:"1"
                },

            ],
            companyInfo:{
                statisticsTime:""
            },
            charts:{
                annualProject:{},
                cooperativeEnterprise:{},
            },
            analysisArr:[],

            //年度项目统计
            yearProjectObj:{
                x:[],
                nums:[],
                price:[]
            },
            MonBiddingPriceList:[],
            mechanismArr:[],//合作代理机构
            bidwayList:[],
            industryBidList:[], //行业招标占比
            registeredcCapitalList:[], //中标企业注册资本分布
            //中标企业年限及个数分布
            ageCountList:[
                ["product" ],
                ["<1年" ],
                ["1-2年" ],
                ["3-5年"],
                [">5年"],
                ["年限不详"],
            ],
            BidDynamic:[],//招标动态
            hzqyList:[],//中标企业
        };
    },
    computed: {
    },
    watch: {},
    methods: {
        unitDetailsAfterQuery(rows , data) {
            this.setCzc(['查企业-详情-招标分析（企业画像）', '翻页' , '单位联系人', this.$refs.analysispage.currentPage ,'checkEnterpriseBid-page-unitDetails'])
        },
        cooperateAgentAfterQuery(rows , data) {
            this.setCzc(['查企业-详情-招标分析（企业画像）', '翻页' , '合作代理机构', this.$refs.page.currentPage ,'checkEnterpriseBid-page-cooperateAgent'])
        },


        int(){
            // 年度项目统计
            this.charts.annualProject = {
                x:["2019","2020","2021","2022"],
                num:[2, 3, 7, 6],
                money:[2.0, 4.9, 7.0, 23.2]
            };

            // 中标企业注册资本分布
            this.charts.cooperativeEnterprise = {
                x:["100-200万","1000-5000万","1亿-2亿","10亿以上"],
                // num:[2, 3, 7, 6],
                num:[]
            } 
        },
        typeName(type){
            let obj = {
                "1":"个",
                "2":"万"
            }
            return obj[type]
        },


        //获取统计信息
        getStatisticalInfo(){
            let that = this;
            that.$get(`${that.$store.state.api.tbUrl}/zbanalysis/getprojectbase.json`,{
                company:that.company
            },function(data){
                this.statisticsArr[0].num = data.zbcount;
                this.statisticsArr[1].num = Math.floor(data.totalprice) / 10000;
                this.statisticsArr[2].num = data.wincount;
            })
        },
        //获取统计信息时间段
        getStatisticalTime:function(){
            let that = this;
            that.$get(`${that.$store.state.api.tbUrl}/zbanalysis/getsearchrange.json`,{},function(data){
                this.companyInfo.statisticsTime = data.start + '~' + data.end;
            })
        },

        //获取年段项目统计
        getYearProject:function(){
            let that = this;
            that.$get(`${that.$store.state.api.tbUrl}/zbanalysis/projectpricebyyear.json`,{
                company:that.company,
            },function(data){
                data.forEach((item) =>{
                    this.yearProjectObj.x.push(item.year);
                    this.yearProjectObj.nums.push(item.count);
                    this.yearProjectObj.price.push(Math.floor(item.price) /10000);
                })
            })
        },

        //获取月度中标金额规模统计
        getMonBiddingPrice(){
            let that = this;
            that.$ajax({
                type: "get",
                url: `${that.$store.state.api.tbUrl}/zbanalysis/projectpricebymonth.json`,
                data: {
                    company:that.company,
                },
                callback: function (data) { 
                    this.MonBiddingPriceList = data;
                    // data.forEach(function(item){
                    //     item.infos.forEach(function(i){
                    //         console.log(Math.floor(i.total) / 10000);
                    //     })
                    // })
                },
                error: function () {},
            });
        },
        
        //获取各类招标方式占比
        getBidType(){
            let that = this;
            that.$get(`${that.$store.state.api.tbUrl}/zbanalysis/projecttypeproportion.json`,{
                company:that.company
            },function(data){
                this.bidwayList = data;
                this.bidwayList.forEach((val,index) => {
                    if(val.bidmethod == null){
                        this.bidwayList[index].bidmethod = '未知类型'
                    }
                })
            })
        },

        //获取行业招标占比
        getIndustryBid(){
            let that = this;
            that.$get(`${that.$store.state.api.tbUrl}/zbanalysis/industryproportion.json`,{
                company:that.company
            },function(data){
                if(!!data){
                    this.industryBidList = data;
                } 
            })
        },

        //获取中标企业注册资本分布
        getRegisteredCapital(){
            let that = this;
            that.$ajax({
                type: "get",
                url: `${that.$store.state.api.tbUrl}/zbanalysis/capitaldistribute.json`,
                data: {
                    company:that.company
                },
                callback: function (data) {
                    that.registeredcCapitalList = data.filter(item =>{
                        return item.counts != 0 
                    });
                },
                error: function () {},
            });
        },

        //获取中标企业年限及个数分布
        getRegisteredYear(){
            let that = this;
            that.$get(`${that.$store.state.api.tbUrl}/zbanalysis/eatablishdistribute.json`,{
                company:that.company
            },function(data){
                let cityUnknown = data.filter(item =>{
                    return item.city == '地市不详';
                })
                let cityKnown = data.filter(item =>{
                    return item.city != '地市不详';
                })

                data = [...cityKnown, ...cityUnknown];

                data.forEach(function(item){
                    that.ageCountList[0].push(item.city)
                    that.ageCountList[1].push(item.range1)
                    that.ageCountList[2].push(item.range2)
                    that.ageCountList[3].push(item.range3) 
                    that.ageCountList[4].push(item.range4)
                    that.ageCountList[5].push(item.range5)
                })
            })
        },

        //获取招标动态 埋点
        bidDynamicAfter(val){
            this.setCzc(['查企业-详情-招标分析（企业画像）', '翻页' , '招标动态', val.current ,'checkEnterpriseBid-page-bidDynamics']);
        },

        //获取中标企业 埋点
        hzqyAfter(val){
            this.setCzc(['查企业-详情-招标分析（企业画像）', '翻页' , '中标企业', val.current ,'checkEnterpriseBid-page-winEnterprise']);
        },

        //获取招标动态收藏
        getBidDynamicCollect:function(index){
            let that = this;
            that.$get(`${that.$store.state.api.tbUrl}/zbanalysis/getprojectlist.json`,{
                sortorder:'desc',
                sortname:'publishtime',
                pageindex:index+1,
                pagesize:1,
                company:that.company,
            },function(data){
                that.$set(that.BidDynamic,index,data.rows[0]);
            })
        },

        //获取中标企业关注
        getHzqyListFollow:function(index){
            let that = this;
            that.$get(`${that.$store.state.api.tbUrl}/zbanalysis/winnersinfo.json`,{
                sortorder:'desc',
                sortname:'resdate',
                pageindex:index+1,
                pagesize:1,
                company:that.company,
            },function(data){
                that.$set(that.hzqyList,index,data.rows[0]);
            })
        },

        zbdtTitleClick:function(val){
            this.openNotice(val.guid,val.noticetype,false);
        },
        
        companyHandle:function(val){
            if (!val.guid) {
                return ShowMsg('当前企业数据暂无数据', 'warning');
            }

            this.goto({
                path: './portraits',
                query: {
                    guid: val.guid,
                    company: val.company,
                },
            });
        },

    },
    
    mounted() {
        this.int();
        this.getStatisticalInfo();
        this.getStatisticalTime();
        this.getYearProject();
        this.getMonBiddingPrice();
        this.getBidType();
        this.getIndustryBid();
        this.getRegisteredCapital();
        this.getRegisteredYear();
    },
    
};
</script>

<style lang="scss" scoped>
@import "@css/var.scss";
.zb-analysis {

    .items {
        display: flex;
        flex-wrap: wrap;
        
        &>div {
            width: 375px;
            margin-top: 10px;
            margin-left: 16px;
            
            &:nth-child(3n+1){
                margin-left: 0;
            }

            &:nth-child(-n+3){
                margin-top: 0;
            }
        }
    }

    .statistics {
        .statistics-time {
            color: $infoColor;
        }

        .statistics-items {
            display: flex;
            justify-content: space-between;
            padding: 28px 40px;
            font-size: 12px;
            background-color: #f9f9f9;

            .top{
                display: flex;
                align-items:flex-end;

                .num {
                    font-size: 17px;
                    margin-right: 3px;
                    font-weight: 600;
                }
            }

            .title {
                margin-top: 15px;
            }
        }
    }

    .charts {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        margin-top: 30px;

        &>div {
            width: 560px;
        }
    }

    .mechanism {
        .mechanism-items {
            display: flex;
            background-color: #f9f9f9;
            .mechanism-items-left , .mechanism-items-right{
                // flex:1;
                width: 50%;
                padding:10px 20px;
            }
            .mechanism-item {
                display: flex;
                justify-content: space-between;
                width: 100%;
                margin-top: 10px;
                color: $infoColor;

                &>div:first-child{
                    width: 300px;
                }
            }
        }
    }

    .bottom {
        display: flex;
        justify-content: space-between;
        margin-top: 15px;

        &>div {
            width: 560px;
        }

        .bottom-left{
            .bottom-right-items{
                margin-top: 15px;

                .title_con{
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    p{
                        font-size: 15px;
                        font-weight: 600;
                        width: 80%;
                        white-space: nowrap;
                        overflow: hidden; 
                        text-overflow: ellipsis;
                        span{
                            cursor: pointer;
                        }
                    }
                    p span:hover{
                        color:$primaryColor
                    }
                    span{
                        margin-right: 10px;
                    }

                    & > div{
                        display: flex;
                        align-items: center;
                    }
                    
                }
                .detail_con{
                    margin-top: 15px;
                    line-height: 1.6em;
                }
            }
            
            .re-span {
                font-size: 14px;
                color: #999;
                font-weight: 600;
            }
        }

        .bottom-right{
            .bottom-right-items{
                margin-top: 15px;
                .title_con{
                    display: flex;
                    align-items: center;
                    justify-content: space-between;

                    p{
                        font-size: 15px;
                        font-weight: 600;
                        max-width: 460px;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        span{
                            cursor: pointer;
                        }
                    }

                    p span:hover{
                        color:$primaryColor
                    }

                    & > div{
                        display: flex;
                        align-items: center;
                    }
                }
                .detail_con{
                    // margin-top: 15px;
                    // line-height: 1.6em;
                    margin-top: 3px;
                    span{
                        margin-right: 20px;
                        display: inline-block;
                        margin-top: 3px;
                    }
                }
                
            }
        }
    }
    .pagination{
        margin-top: 20px;
    }

    .block-item{
        margin: 20px 0;
    }
}
</style>